// The API isBadVersion is defined for you.
// bool isBadVersion(int version);

class Solution {
public:
    int firstBadVersion(int n) {
        return findFirst(0,n);
    }
    int findFirst(int l,int r){
        int m;
        while(l<r){
            m=l+floor((r-l)/2.0);
            if(isBadVersion(m)){r=m;}
            else{l=m+1;}
        }
        return l;
    }
};

